package com.yidu.service.impl;

import com.yidu.dao.BlogsUserMapper;
import com.yidu.domain.BlogsUser;
import com.yidu.domain.vo.BlogsUserVo;
import com.yidu.service.LoginOrRegisterService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * @author: 肖楚科
 * @date: 2021/1/25
 * @time: 14:03
 * @blog: com.yidu.service.impl
 * @description:
 */
@Service
public class LoginOrRegisterServiceImpl implements LoginOrRegisterService {
    @Resource
    BlogsUserMapper blogsUserMapper;

    @Override
    public int insertSelective(BlogsUserVo blogsUserVo) {
        BlogsUser blogsUser = new BlogsUser();
        BeanUtils.copyProperties(blogsUserVo,blogsUser);
        blogsUser.setUserBirthday(LocalDate.parse(blogsUserVo.getUserBirthday()));
        blogsUser.setUserRegtime(LocalDate.now());
        blogsUser.setUserAge(((int)LocalDate.now().toEpochDay())/365-((int)(blogsUser.getUserBirthday().toEpochDay()))/365);
        return blogsUserMapper.insertSelective(blogsUser);
    }

    @Override
    public int check(String userName, String userPassword) {
        return blogsUserMapper.check(userName,userPassword);
    }

    @Override
    public int check(String userName) {
        return blogsUserMapper.check(userName);
    }
}
